<?php
class CommonUtils{

	/**
	 * 获取DB Object
	 * @param $type int
	 * @return RecordObject
	 **/
	public static function getDbConn($type=0,$destination='db')
	{
		static $conn=array();
		static $target = array("reader","writer");
		static $class = array("ReadableRecordFactory","WritableRecordFactory");

		$config = ConfigReaderFactory::getInstance()->getConfigReader(AC::REPORT_TOOL_DB_CONFIG)->getConfig();
		$db     = $config->$destination;
		$conn_name = $type.$destination;
		if(!isset($conn[$conn_name])){
			$conn[$conn_name] = new $class[$type] ($db->$target[$type],$db->user,(string)$db->pwd,$db->name);
		}
		return $conn[$conn_name];
	}
}
?>
